package com.wu.common.utils;


import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ReadImgUrls {
    public ReadImgUrls() {
    }

    public static String[] getImgs(String content) {
        String img = "";
        String str = "";
        String[] images = null;
        String regEx_img = "(<img.*src\\s*=\\s*(.*?)[^>]*?>)";
        Pattern p_image = Pattern.compile(regEx_img, 2);
        Matcher m_image = p_image.matcher(content);

        while(m_image.find()) {
            img = m_image.group();
            Matcher m = Pattern.compile("src\\s*=\\s*\"?(.*?)(\"|>|\\s+)").matcher(img);

            while(m.find()) {
                String tempSelected = m.group(1);
                if ("".equals(str)) {
                    str = tempSelected;
                } else if (tempSelected.indexOf("mmbiz.qpic.cn") == -1) {
                    str = str + "," + tempSelected;
                }
            }
        }

        if (content.indexOf("background-image") > 0) {
            String regEx_bg = "(background-image\\s*:\\s*url\\s*\\((&#39;)?http://\\S*\\);)";
            p_image = Pattern.compile(regEx_bg, 2);
            m_image = p_image.matcher(content);

            while(m_image.find()) {
                img = m_image.group();
                if (img.indexOf("&#39;") > 0) {
                    img = img.replace("&#39;", "");
                }

                Matcher m = Pattern.compile("\\(\\s*(http://\\S*)\\s*\\);").matcher(img);

                while(m.find()) {
                    String tempSelected = m.group(1);
                    if ("".equals(str)) {
                        str = tempSelected;
                    } else if (tempSelected.indexOf("mmbiz.qpic.cn") == -1) {
                        str = str + "," + tempSelected;
                    }
                }
            }
        }

        if (!"".equals(str)) {
            images = str.split(",");
        }

        return images;
    }

    public static void main(String[] args) {
        String baseImageUrl = System.getProperty("user.dir");
        String var2 = "http://www.jeewx.com/jeewx";

        try {
            String c = FileUtils.readFile("D:/workspace-JEECGONE/jeewx-api/src/main/java/org/jeewx/api/wxsendmsg/uploadimg/1.html");
            String[] urls = getImgs(c);
            String[] var5 = urls;
            int var6 = urls.length;

            for(int var7 = 0; var7 < var6; ++var7) {
                String url = var5[var7];
                System.out.println(url);
            }
        } catch (IOException var9) {
            var9.printStackTrace();
        }

    }
}

